home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / After Effects 3.1 SDK Mac / Examples / UI Samples / Custom UI in comp⁄layer / AEFX_Sample.c next >
Encoding:
C/C++ Source or Header  |  1996-11-06  |  5.8 KB  |  240 lines  |  [TEXT/CWIE]

  1. /**
  2.     AEFX_Sample.c
  3.     
  4.     Part of the Adobe After Effects 3.1 SDK    
  5.     Copyright (c)1993-96, Adobe Systems Inc, All Rights Reserved.
  6.     
  7.     A simple After Effects plug-in with a custom user interface demonstrating
  8.     the use of PF_Cmd_Event.
  9.  
  10.     Revision History
  11.         1.0, created by dmw
  12.         1.1, Added call to AEFX_CLR_STRUCT macro to clear out PF_ParamDef, ba, 6 Nov 96
  13. **/
  14.  
  15. #include "AEFX_Sample.h"
  16.  
  17.  
  18. static PF_Err About (
  19.     PF_InData        *in_data,
  20.     PF_OutData        *out_data,
  21.     PF_ParamDef        *params[],
  22.     PF_LayerDef        *output )
  23. {
  24.     PF_SPRINTF(out_data->return_msg,
  25.         "%s, v%d.%d\r%s",
  26.         NAME, MAJOR_VERSION, MINOR_VERSION, DESCRIPTION);
  27.  
  28.     return PF_Err_NONE;
  29. }
  30.  
  31.  
  32. static PF_Err GlobalSetup (
  33.     PF_InData        *in_data,
  34.     PF_OutData        *out_data,
  35.     PF_ParamDef        *params[],
  36.     PF_LayerDef        *output )
  37. {
  38.     PF_Err    err = PF_Err_NONE;
  39.  
  40.     out_data->out_flags |= PF_OutFlag_USE_OUTPUT_EXTENT | PF_OutFlag_CUSTOM_UI;
  41.  
  42.     out_data->my_version = PF_VERSION(MAJOR_VERSION, MINOR_VERSION,
  43.                                       BUG_VERSION, STAGE_VERSION, BUILD_VERSION);
  44.  
  45.     return err;
  46. }
  47.  
  48.  
  49. static PF_Err ParamsSetup (
  50.     PF_InData        *in_data,
  51.     PF_OutData        *out_data,
  52.     PF_ParamDef        *params[],
  53.     PF_LayerDef        *output )
  54. {
  55.     PF_Err             err = PF_Err_NONE;
  56.     PF_ParamDef        def;
  57.     
  58.     /* Always clear out the PF_ParamDef structure before adding your parameters,
  59.      * this macro will do that.
  60.      */
  61.     AEFX_CLR_STRUCT(def);
  62.     
  63.     def.param_type = PF_Param_FIX_SLIDER;
  64.     PF_STRCPY(def.name, "Horizontal Radius");
  65.     def.u.fd.value_str[0] = '\0';    def.u.fd.value_desc[0] = '\0';
  66.     def.u.fd.dephault = def.u.fd.value = SAM_RADIUS_DFLT;
  67.     def.u.fd.slider_min = def.u.fd.valid_min = SAM_RADIUS_MIN;
  68.     def.u.fd.valid_max = SAM_RADIUS_BIG_MAX;
  69.     def.u.fd.slider_max = SAM_RADIUS_MAX;
  70.     def.u.fd.precision = 1;
  71.     if (err = PF_ADD_PARAM(in_data, -1, &def)) return err;
  72.  
  73. //    AEFX_CLR_STRUCT(def);
  74.  
  75.     def.param_type = PF_Param_FIX_SLIDER;
  76.     PF_STRCPY(def.name, "Vertical Radius");
  77.     def.u.fd.value_str[0] = '\0';    def.u.fd.value_desc[0] = '\0';
  78.     def.u.fd.dephault = def.u.fd.value = SAM_RADIUS_DFLT;
  79.     def.u.fd.slider_min = def.u.fd.valid_min = SAM_RADIUS_MIN;
  80.     def.u.fd.valid_max = SAM_RADIUS_BIG_MAX;
  81.     def.u.fd.slider_max = SAM_RADIUS_MAX;
  82.     def.u.fd.precision = 1;
  83.     if (err = PF_ADD_PARAM(in_data, -1, &def)) return err;
  84.     
  85. //    AEFX_CLR_STRUCT(def);
  86.  
  87.     def.param_type = PF_Param_POINT;
  88.     PF_STRCPY(def.name, "Center");
  89.     def.u.td.x_dephault = def.u.td.x_value = SAM_PTX_DFLT;
  90.     def.u.td.y_dephault = def.u.td.y_value = SAM_PTY_DFLT;
  91.     def.u.td.restrict_bounds = FALSE;
  92.     err = PF_ADD_PARAM(in_data, -1, &def);
  93.  
  94.     if (!err) {
  95.         PF_CustomUIInfo        ci;
  96.         
  97.         ci.events = PF_CustomEFlag_LAYER | PF_CustomEFlag_COMP;
  98.          
  99.         ci.comp_ui_width = ci.comp_ui_height = 0;
  100.         ci.comp_ui_alignment = PF_UIAlignment_NONE;
  101.         
  102.         ci.layer_ui_width = ci.layer_ui_height = 0;
  103.         ci.layer_ui_alignment = PF_UIAlignment_NONE;
  104.         
  105.         ci.preview_ui_width = ci.preview_ui_height = 0;
  106.         ci.layer_ui_alignment = PF_UIAlignment_NONE;
  107.  
  108.         err = (*(in_data->inter.register_ui))(in_data->effect_ref, &ci);
  109.     }
  110.  
  111.     out_data->num_params = SAM_NUM_PARAMS;
  112.     
  113.     return err;
  114. }
  115.  
  116.  
  117. static PF_Err Render (
  118.     PF_InData        *in_data,
  119.     PF_OutData        *out_data,
  120.     PF_ParamDef        *params[],
  121.     PF_LayerDef        *output )
  122. {
  123.     register long         x, y;
  124.     long                w = output->width,
  125.                         h = output->height;
  126.     long                gutter = (output->rowbytes / 4) - w;
  127.     PF_Pixel            *bop_out = output->data,
  128.                         *bop_in = (params[0]->u.ld.data);
  129.                         
  130.     PF_Err                 err = PF_Err_NONE;
  131.     double                rad_x, rad_y, y_ratio;
  132.     double                center_x, center_y, dist, dx, dy, dy_sqr;
  133.     double                rad_x_inv;
  134.     double                y_ratio_inv;
  135.  
  136.     double (*sqrt_t)(double) = ((PF_UtilCallbacks *)in_data->utils)->ansi.sqrt;
  137.     double (*sin_t)(double) = ((PF_UtilCallbacks *)in_data->utils)->ansi.sin;
  138.     
  139.     long    min_x, max_x, min_y, max_y;
  140.     
  141.     
  142.     min_x = output->extent_hint.left;
  143.     min_y = output->extent_hint.top;
  144.     max_x = output->extent_hint.right;
  145.     max_y = output->extent_hint.bottom;
  146.     
  147.     center_x = FIX_2_FLOAT(params[SAM_PT]->u.td.x_value);
  148.     center_y = FIX_2_FLOAT(params[SAM_PT]->u.td.y_value);
  149.     rad_x = FIX_2_FLOAT(params[SAM_X_RADIUS]->u.fd.value);
  150.     rad_y = FIX_2_FLOAT(params[SAM_Y_RADIUS]->u.fd.value);
  151.     rad_x /= in_data->downsample_x.den;
  152.     rad_y /= in_data->downsample_y.den;
  153.     rad_x *= in_data->downsample_x.num;
  154.     rad_y *= in_data->downsample_y.num;
  155.  
  156.     rad_x_inv = 1.0 / rad_x;
  157.     y_ratio = rad_y * rad_x_inv;
  158.     y_ratio_inv = 1.0 / y_ratio;
  159.  
  160.     if (rad_x == 0 || rad_y == 0)            
  161.         return PF_COPY(¶ms[0]->u.ld, output, NULL, NULL);
  162.     
  163.     for (y=0; y<h; y++) {
  164.         dy = (double)y - center_y;
  165.         dy_sqr = (dy * y_ratio_inv);    /* convert to be rad_x relative */
  166.         dy_sqr *= dy_sqr;
  167.  
  168.         if (dy > rad_y || dy < -rad_y || y < min_y || y > max_y) {
  169.             for (x = w; x > 0; x--)    *bop_out++ = *bop_in++;
  170.                 
  171.         } else for (x = 0; x < w; x++) {
  172.             dx = (double)x - center_x;
  173.  
  174.             if (dx > rad_x || dx < -rad_x || x < min_x || x > max_x) {
  175.                 *bop_out++ = *bop_in++;
  176.                 continue;
  177.             }
  178.  
  179.             dist = sqrt_t(dx * dx + dy_sqr);
  180.             if (dist == 0 || dist >= rad_x) {
  181.                 *bop_out++ = *bop_in++;
  182.                 continue;
  183.             } else {
  184.                 bop_out->red = bop_out->alpha = 255;
  185.                 bop_out->blue = bop_out->green = 0;
  186.                 
  187.             }
  188.  
  189.             bop_in++;    bop_out++;
  190.         }
  191.         bop_in += gutter;
  192.         bop_out += gutter;
  193.  
  194.         if (((y&1) != 0) &&        /* only do alternating scanlines */
  195.             (err = PF_PROGRESS(in_data, y+1, h)))
  196.             goto bail;
  197.     }
  198.  
  199. bail:
  200.     return err;
  201. }
  202.  
  203.  
  204. PF_Err main (
  205.  
  206.     PF_Cmd            cmd,
  207.     PF_InData        *in_data,
  208.     PF_OutData        *out_data,
  209.     PF_ParamDef        *params[],
  210.     PF_LayerDef        *output,
  211.     void            *extra )
  212. {
  213.     PF_Err        err = PF_Err_NONE;
  214.     SAM_DECLARE_A4
  215.     
  216.     SAM_SET_A4
  217.  
  218.     switch (cmd) {
  219.     case PF_Cmd_ABOUT:
  220.         err = About(in_data,out_data,params,output);
  221.         break;
  222.     case PF_Cmd_GLOBAL_SETUP:
  223.         err = GlobalSetup(in_data,out_data,params,output);
  224.         break;
  225.     case PF_Cmd_PARAMS_SETUP:
  226.         err = ParamsSetup(in_data,out_data,params,output);
  227.         break;
  228.     case PF_Cmd_RENDER:
  229.         err = Render(in_data,out_data,params,output);
  230.         break;
  231.     case PF_Cmd_EVENT:
  232.         err = HandleEvent(in_data,out_data,params,output,extra);
  233.         break;
  234.     }
  235.  
  236.     SAM_RESTORE_A4
  237.     
  238.     return err;
  239. }
  240.